<template>
	<view class="list">
		<view class="err" v-show="flag">搜索结果为空</view>
		<view class="err" v-show="options.uid!=null&&list.length==0">还没有收藏影片</view>
		<view class="list-item" v-for="(item,index) in list" :key="index" @click="goDetail(item.id)">
			<image :src="item.cover_url" mode="aspectFill"></image>
			<view class="text">{{ item.title }}</view>
			<view class="third">
				<uni-rate style="margin-top: 3px;" :value="item.grade*0.5" size="10px"></uni-rate>
				<view>{{ item.grade }}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				flag: false,
				collectflag: false,
				list: []
			}
		},
		onLoad(options) {
				if(options.value!=null)
					this.getSearchList(options.value)
				if(options.id!=null)
					this.getClassList(options.id)
				if(options.uid!=null)
					this.getCollect(options.uid)
		},
		methods: {
			getSearchList(value) {
				uni.request({
					url: 'http://www.yingke.com/Index/movieSearch?title='+value,
					method: 'POST',
					success: (res) => {
						if(res.data.data.length!=0)
							this.list = res.data.data
						else
							this.flag = true
					}
				})
			},
			getClassList(id) {
				uni.request({
					url: 'http://www.yingke.com/Index/getMovieByClassId?class_id='+id,
					method: 'POST',
					success: (res) => {
						this.list = res.data.data
					}
				})
			},
			getCollect(id) {
				uni.request({
					url: 'http://www.yingke.com/index/myCollect?uid='+id,
					method: 'POST',
					success: (res) => {
						this.list = res.data.data
					}
				})
			},
			goDetail(id){
				uni.navigateTo({
					url: '../mov-detail/mov-detail?data='+id
				})
			},
		}
	}
</script>

<style lang="scss">
	.list{
		width: 380px;
		margin: 10px auto;
		.list-item{
			display: inline-block;
			margin-left: 10px;
			margin-bottom: 10px;
			margin-right: -15px;
			image{
				width: 80px;
				height: 125px;
				border-radius: 10px;
			}
			.third{
				display: flex;
				color: #ffca3e;
			}
		}
		.text{
			width: 95px;
			height: 20px;
			overflow: hidden;
			text-overflow: ellipsis;
		}
		.err{
			font-size: 15px;
			font-weight: bold;
			line-height: 100px;
			text-align: center;
		}
	}
</style>
